/**
 * Created by Administrator on 2015-02-11.
 */


require.config({
    paths: {
        //这里只定义插件以及灵魂的外部入口，插件内部所依赖的在插件内部的ready函数内定义
        MDEditor:'../../ui/MDEditor/MDEditor.js',
        modal:'../../ui/modal/modal.js',
        stb:'../../plugins/stb/stb.js',

        //soul
        nav:'../../package/nav/nav.js',
        home:'../../package/home/home.js',
        list:'../../package/list/list.js',
        edit:'../../package/edit/edit.js',
        art:'../../package/art/art.js',
        user:'../../package/user/user.js',


        //admin
        ahome:'../../package/ahome/ahome.js',
        theme:'../../package/theme/theme.js',
        addClass:'../../package/addClass/addClass.js'
    }

});

// 预先定义好的TSY，方便操作接口的时候直接调用
var tsy;
function setTsy(){
    tsy = getCookie("tsy");
}
setTsy();

//接口地址
//var apiURL = 'http://demo.api.tansuyun.cn/index.html?i=';
var apiURL = 'https://api.tansuyun.cn?i=';

//开放的权限下的登录验证之后的操作
var openAccessDoing = {
    haveLogin: function () {


    },
    notLogin: function () {

    }
};
//严格的权限下的登录验证之后的操作
var seriousAccessDoing = {
    haveLogin: function () {
//        nav.haveLogin()
    },
    notLogin: function () {

        nav.stbIn()
        tip.on('您尚未登录或登录已失效，请登录后再执行本次操作！', 0);
        setTimeout(function () {
            tip.off('您尚未登录或登录已失效，请登录后再执行本次操作！', 0);
        }, 15000);
        setTimeout(function(){
            history.go(-1)
        },100)

    }
};

function logErr(res){
    console.log(res.c+":"+res.m)
}
function getScrollTop()
{
    var scrollTop=0;
    if(document.documentElement&&document.documentElement.scrollTop)
    {
        scrollTop=document.documentElement.scrollTop;
    }
    else if(document.body)
    {
        scrollTop=document.body.scrollTop;
    }
    return scrollTop;
}

//getCookie用于取cookie中的数据

function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}
//setCookie用于将数据存于cookie中

function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//阻止浏览器默认事件，阻止在文本框外点击Backspace返回上一个页面
function preventBackspace(){
    document.getElementsByTagName("body")[0].onkeydown = function(event){
        //获取事件对象
        var elem = event.relatedTarget || event.srcElement || event.target ||event.currentTarget;
        //判断按键为backSpace键
        if(event.keyCode == 8){
            //判断是否需要阻止按下键盘的事件默认传递
            var name = elem.nodeName.toUpperCase();;
            if(name != 'INPUT' && name != 'TEXTAREA'){
                return false;
            }
        }
    }
}
preventBackspace();